﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour {

	public static GameManager instance;

    public GameObject gameOverDialog; //游戏结束窗口

	public int Easy = 5;
	public int Middle = 10;
	public int Difficult = 15;

	public int difficult;//游戏难度

    public bool starClear = false;//是否所有星球都消灭了
    public bool isOver = false; //当前掠夺是否结束
	

	void Awake()
	{
		instance = this;
		
	}

	void Start () {
		setDifficult();
    }
	
	void Update () {
        //所有星球都消灭了，玩家是否捡完宝箱，如果捡完就游戏结束返回主页面
        if (starClear==true&&isOver==false)
        {
            //判断是否捡完所有宝箱
            if (TreasureBoxManager._instance.tempBoxNum == TreasureBoxManager._instance.currBoxNum)
            {
                //更新所得的宝箱数量 新的+旧的(仓库未开的)
                TreasureBoxManager._instance.SetBoxNum(TreasureBoxManager._instance.GetAllBox());
                //显示游戏结束界面
                GameObject.Instantiate(gameOverDialog);
                //打印各种宝箱的数量,用于调试
                //TreasureBoxManager._instance.GetBoxTypeNum(); 
                //当前掠夺已经结束  
                isOver = true;
                //跳出循环，顺便恢复原来的值
                starClear = false;
            }
        }
	}

	//设置游戏的难度
	//默认设置难度为简单,根据难度初始化信息
	void setDifficult(){
        isOver=false;
        //初始化宝箱数据
        TreasureBoxManager._instance.Init();
        difficult = Easy;
		/*
		在这里接收UI传过来的难度
		 */
		if(difficult == Easy){
			StarSpawn.instance.SetDiffcultPro(5,5,5,5,1);
		}else if(difficult == Middle){
			StarSpawn.instance.SetDiffcultPro(5,5,5,5,5);
		}else if(difficult == Difficult){
			StarSpawn.instance.SetDiffcultPro(5,5,5,5,5);
		}
	}


	
	
}
